package com.agritech.machine;

/**
 * 播种机类
 * 实现了农业机械抽象类，提供播种机特有的功能
 */
public class Seeder extends AgriculturalMachine {
    private int seedCapacity; // 种子容量
    private int currentSeedAmount; // 当前种子量
    private double seedingDepth; // 播种深度

    public Seeder(String id) {
        super(id, "智能播种机");
        this.seedCapacity = 1000;
        this.currentSeedAmount = 1000;
        this.seedingDepth = 5.0; // 默认播种深度(厘米)
    }

    @Override
    public void start() {
        System.out.println(getType() + " [" + getId() + "] 启动中，检查系统...");
        if (currentSeedAmount < 100) {
            System.out.println("警告: 种子余量不足，请及时补充！");
        }
        updateStatus("工作中");
        System.out.println(getType() + " [" + getId() + "] 已启动，准备播种作业");
    }

    @Override
    public void stop() {
        System.out.println(getType() + " [" + getId() + "] 正在停止作业...");
        updateStatus("空闲");
        System.out.println(getType() + " [" + getId() + "] 已停止，播种作业结束");
    }

    @Override
    public void performTask(String taskDetails) {
        System.out.println(getType() + " [" + getId() + "] 正在执行播种任务: " + taskDetails);
        System.out.println("当前播种深度: " + seedingDepth + "厘米");
        consumeSeed(50); // 消耗种子
        consumeFuel(5.0); // 消耗燃油
    }

    /**
     * 调整播种深度
     * @param depth 新的播种深度(厘米)
     */
    public void adjustSeedingDepth(double depth) {
        System.out.println(getType() + " [" + getId() + "] 调整播种深度从 " + this.seedingDepth + "厘米 到 " + depth + "厘米");
        this.seedingDepth = depth;
    }

    /**
     * 添加种子
     * @param amount 添加的种子量
     */
    public void addSeeds(int amount) {
        this.currentSeedAmount = Math.min(seedCapacity, currentSeedAmount + amount);
        System.out.println(getType() + " [" + getId() + "] 已添加种子，当前种子量: " + currentSeedAmount);
    }

    /**
     * 消耗种子
     * @param amount 消耗的种子量
     */
    private void consumeSeed(int amount) {
        this.currentSeedAmount = Math.max(0, currentSeedAmount - amount);
        System.out.println(getType() + " [" + getId() + "] 已消耗种子，剩余种子量: " + currentSeedAmount);
        if (currentSeedAmount < 100) {
            System.out.println("警告: " + getType() + " [" + getId() + "] 种子余量不足，请及时补充！");
        }
    }

    /**
     * 获取当前种子量
     * @return 当前种子量
     */
    public int getCurrentSeedAmount() {
        return currentSeedAmount;
    }

    /**
     * 获取播种深度
     * @return 播种深度
     */
    public double getSeedingDepth() {
        return seedingDepth;
    }
}